package com.quectel.cms.controller.datav;

import com.quectel.cms.controller.BaseController;
import com.quectel.cms.vo.datav.ConsoleHomeCountAllVo;
import com.quectel.core.module.car.service.CarService;
import com.quectel.core.module.device.service.DeviceService;
import com.quectel.core.module.household.service.HouseholdService;
import com.quectel.core.module.workorder.service.WorkOrderService;
import com.quectel.util.common.Request;
import com.quectel.util.common.Response;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author caolu
 * @email louis.cao@quectel.com
 * @date 2019-05-31 12:10:19
 */
@RestController
@RequestMapping("datav/consoleHome")
@Tag(name = "DataVConsoleHomeController", description = "控制台首页相关api")
public class DataVConsoleHomeController extends BaseController {

    @DubboReference
    private DeviceService deviceService;
    @DubboReference
    private HouseholdService householdService;
    @DubboReference
    private CarService carService;
    @DubboReference
    private WorkOrderService workOrderService;

    @GetMapping("countAll")
    @Operation(summary = "通过小区id,对人口/设备/车辆/工单进行统计")
    public Response<ConsoleHomeCountAllVo> countHousehold(
            @Parameter(description = "小区id") @RequestParam(required = false) Long villageId
    ) {
        Map<String, Object> params = Request.parseParams(httpServletRequest);
        super.fillAuthorityData(params);

        ConsoleHomeCountAllVo consoleHomeCountAllVo = new ConsoleHomeCountAllVo();
        consoleHomeCountAllVo.setHouseholdCount(householdService.queryTotal(params));
        consoleHomeCountAllVo.setDeviceCount(deviceService.queryTotal(params));
        consoleHomeCountAllVo.setCarCount(carService.queryTotal(params));
        consoleHomeCountAllVo.setWorkOrderCount(workOrderService.queryTotal(params));

        return Response.<ConsoleHomeCountAllVo>ok().wrap(consoleHomeCountAllVo);
    }
}
